package com.example.question.array;

public class Code14_941 {

    public boolean validMountainArray(int[] arr) {
        if (arr.length < 3) {
            return false;
        }

        int maxIndex = 0;
        int maxValue = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] > maxValue) {
                maxValue = arr[i];
                maxIndex = i;
            }
        }
        if (maxIndex == 0 || maxIndex == arr.length - 1) {
            return false;
        }

        for (int i = 1; i < maxIndex; i++) {
            if (arr[i] >= arr[maxIndex] || arr[i] <= arr[i - 1]) {
                return false;
            }
        }
        for (int i = maxIndex + 1; i < arr.length; i++) {
            if (arr[i] >= arr[maxIndex] || arr[i] >= arr[i - 1]) {
                return false;
            }
        }
        return true;
    }
}
